/**
author: dk
*/

(function(win) {
	var dkit = {};
	dkit.$ = function(){
		var args = arguments;
		if(typeof args[0] == 'string'){
			if(document.getElementById(args[0])){
				return document.getElementById(args[0]);
			} else {
				return null;
			}
		}else{
			return arguments[0];
		}
	
};
function  clickPost(){
	$(".submit-idea").attr("disabled","disabled");
	var verifyPhone=/^1[3|5|8][0-9]\d{8}$/;
	var ideaValue=$(".depict-idea").val();
	var phoneValue=$(".import-phone").val();
	var errorInfo=$("#errorInfo");
	var errorInfoSpan=$("#errorInfo").find("span");
	if(ideaValue==""){
		errorInfo.css("visibility","visible");
		errorInfoSpan.text("意见不能为空!");
		$(".submit-idea").removeAttr("disabled");
		return;
	}
	if(phoneValue!=""){
		if(!(verifyPhone.test(phoneValue))){
			errorInfo.css("visibility","visible");
			errorInfoSpan.text("手机号格式不正确!");
			$(".submit-idea").removeAttr("disabled");
			return;
		}
	}else{
		errorInfo.css("visibility","visible");
		errorInfoSpan.text("手机号不能为空!");
		$(".submit-idea").removeAttr("disabled");
		return;
	}
	errorInfo.css("visibility","hidden");
	$(".submit-idea").val("正在发送中...");
	$.ajax({
		type:"post",
		dataType:"json",
		url:"/api/ajax-user-fb",
		data:{content:ideaValue,mobile:phoneValue},
		success:function(data,status){
			if(data.code) {
			
				$(".idea-firstPage").fadeOut();
				$(".idea-secondPage").fadeIn();
			}else {
				errorInfo.css("visibility","visible");
				errorInfoSpan.text("提交失败："+data.message);
				$(".submit-idea").val("发布意见");
				$(".submit-idea").removeAttr("disabled");
			}
		},
		error:function(XMLHttpRequest, textStatus){
			errorInfo.css("visibility","visible");
			errorInfoSpan.text("网络不给力...");
			$(".submit-idea").val("发布意见");
			$(".submit-idea").removeAttr("disabled");
		}
	});
}


	dkit.getElementByClassName = function(className, tag, parent) {
        parent = parent || document;
        if (!(parent = $(parent))) {
            return false;
        }
        var allTags = (tag == '*' && parent.all) ? parent.all : parent.getElementsByTagName(tag);
        var matchingElements = new Array();
        className = className.replace(/\-/g, '\\-');
        var regex = new RegExp('(^|\\s)' + className + '(\\s|$)');
        var element;
        for (var i = 0, length = allTags.length; i < length; i++) {
            element = allTags[i];
            if (regex.test(element.className)) {
                matchingElements.push(element);
            }
        }
        return matchingElements;
    };
	
	//create element by tag name
	var eles = {
		div: document.createElement('div'),
		ul: document.createElement('ul'),
		li: document.createElement('li'),
		span: document.createElement('span'),
		p: document.createElement('p'),
		a: document.createElement('a'),
		input:document.createElement('input')
	}
	dkit.$c = function(tagName, id, className){
		if(tagName == "input") {
			
			eles[tagName].type = "button";	
			eles[tagName].value = "确定";	
		
		
			
		}
		var ele = eles[tagName].cloneNode(true);
		
		if(id){
			ele.id = id;
		}
		if(className){
			ele.className = className;
		}
		return ele;
	};
	//browser match
	var browserMatch = (function (ua) {
        ua = navigator.userAgent.toLowerCase();
        var match = /(webkit)[ \/]([\w.]+)/.exec(ua) || /(opera)(?:.*version)?[ \/]([\w.]+)/.exec(ua) || /(msie) ([\w.]+)/.exec(ua) || !/compatible/.test(ua) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec(ua) || [];
        return {
            browser: match[1] || "",
            version: match[2] || "0"
        };
    })();
	
    dkit.browser = {};
	
    if (browserMatch.browser) {
        dkit.browser[browserMatch.browser] = true;
        dkit.browser.version = browserMatch.version;
    }
	//事件绑定修复
	function addEvent(node, type, listener) {
		var customEvents = {'fover': 'mouseover', 'fout': 'mouseout'};
        if (typeof(node) == 'string') {
            node = $(node);
        }
        if (!listener.$$guid) {
            listener.$$guid = addEvent.guid++;
        }
        if (!node.events) {
            node.events = {};
        }
        var handlers = node.events[type],
            isRegisted = !! node.events[type];
        if (!handlers) {
            handlers = node.events[type] = {};
        }
        handlers[listener.$$guid] = listener;
        if (!isRegisted) {
            if (node.addEventListener) {
				if(customEvents[type]){
					node.addEventListener(customEvents[type], handleEventFix, false);
				}else{
					node.addEventListener(type, handleEvent, false);
				}
            } else if (node.attachEvent) {
                var tempFunc;
				if(customEvents[type]){
					tempFunc = function () {
						handleEventFix.call(node, window.event);
					};
					type = customEvents[type];
				}else{
					tempFunc = function () {
						handleEvent.call(node, window.event);
					};
					
				}
                node.attachEvent('on' + type, tempFunc);
            } else {
                node['on' + type] = handleEvent;
            }
        }
    }

    addEvent.guid = 1;

    function removeEvent(node, type, handler) {
        if (node.events && node.events[type]) {
            delete node.events[type][handler.$$guid];
        }
    }

    function handleEvent(event) {
        var returnValue = true;
        event = event || window.event;
        event = fixEvent(event, this);
        var handlers = this.events[event.type];
        for (var i in handlers) {
            this.$$handleEvent = handlers[i];
            if (this.$$handleEvent(event) === false) {
                returnValue = false;
            }
        }
        return returnValue;
    }
	
	function handleEventFix(event) {
        var returnValue = true;
        event = event || window.event;
        event = fixEvent(event, this);
		var type = event.type.replace('mouse', 'f');
        var handlers = this.events[type];
        for (var i in handlers) {
            this.$$handleEvent = handlers[i];
			if(checkHover(event, this)){
				if (this.$$handleEvent(event) === false) {
					returnValue = false;
				}
			}
        }
        return returnValue;
    }

    function fixEvent(event, currentTarget) {
        event.preventDefault || (event.preventDefault = fixEvent.preventDefault);
        event.stopPropagation || (event.stopPropagation = fixEvent.stopPropagation);
        event.target || (event.target = event.srcElement);
        event.currentTarget || (event.currentTarget = currentTarget);
        //event.x && (event.x = fixEvent.x);
        //event.y && (event.y = fixEvent.y);
        return event;
    }

    fixEvent.preventDefault = function () {
        this.returnValue = false;
    };
    fixEvent.stopPropagation = function () {
        this.cancelBubble = true;
    };
	
    dkit.addEvent = addEvent;
	dkit.removeEvent = removeEvent;
	
	dkit.bind = function(targetObj, func) {
        var args = Array.prototype.slice.call(arguments).slice(2);
        return function () {
            return func.apply(targetObj, args.concat(Array.prototype.slice.call(arguments)));
        }
    }
	
	dkit.contains = function(parentNode, childNode) {
        return parentNode.contains ? parentNode != childNode && parentNode.contains(childNode) : !! (parentNode.compareDocumentPosition(childNode) & 16);
    }
	
	function checkHover(e, target) {
        if (dk.getEvent(e).type == "mouseover") {
            return !dkit.contains(target, getEvent(e).relatedTarget || getEvent(e).fromElement) && !((getEvent(e).relatedTarget || getEvent(e).fromElement) === target);
        } else {
            return !dkit.contains(target, getEvent(e).relatedTarget || getEvent(e).toElement) && !((getEvent(e).relatedTarget || getEvent(e).toElement) === target);
        }
    }
	
	dkit.getBrowserSize = function() {
        var de = document.documentElement;
        return {
            width: (window.innerWidth || (de && de.clientWidth) || document.body.clientWidth),
            height: (window.innerHeight || (de && de.clientHeight) || document.body.clientHeight)
        }
    }
	
	dkit.getDocSize = function() {
        return {
            width: document.body.scrollWidth,
            height: document.body.scrollHeight
        };
    }
	
	dkit.getNodePosition = function(target) {
        target = $(target)
        if (!target) {
            return null;
        }
        var left = 0,
            top = 0;
        do {
            left += target.offsetLeft || 0;
            top += target.offsetTop || 0;
            target = target.offsetParent;
        } while (target);
        return {
            left: left,
            top: top
        };
    }
	
	dkit.getMousePosition = function(e) {
        var scrollx, scrolly;
        if (typeof(window.pageXOffset) == 'number') {
            scrollx = window.pageXOffset;
            scrolly = window.pageYOffset;
        } else {
            scrollx = document.documentElement.scrollLeft;
            scrolly = document.documentElement.scrollTop;
        }
        return {
            x: e.clientX + scrollx,
            y: e.clientY + scrolly
        }
    }
	//获取滚动条值
	dkit.getScroll = function() {
        var scrollx, scrolly;
        if (typeof(window.pageXOffset) == 'number') {
            scrollx = window.pageXOffset;
            scrolly = window.pageYOffset;
        } else {
            scrollx = document.documentElement.scrollLeft;
            scrolly = document.documentElement.scrollTop;
        }
        return {
            left: scrollx,
            top: scrolly
        };
    }
	//随机数，从m到n
	dkit.ran = function(m, n) {
        return Math.floor((n - m + 1) * Math.random() + m);
    };
	
	var _$ = function (node) {
		if (typeof(node) == 'string') {
			node = dkit.$(node);
		}
		this.node = node;
	};
	_$.prototype = {
		css: function (style, value) { //三个重载方法
			var argNum = arguments.length;
			if (argNum == 1 && typeof(arguments[0]) == 'string') { //按照参数中的样式表的样式名称获取样式的值
				return this.getCss(arguments[0]);
			} else if (argNum == 1 && typeof(arguments[0]) == 'object') { //按照参数中的Json对象设置样式
				var styles = arguments[0];
				for (var i in styles) {
					this.setCss(i, styles[i]);
				}
			} else if (argNum == 2) { //按照参数中的样式名称和值对指定样式进行设置
				this.setCss(arguments[0], arguments[1]);
			}
			return this;
		},
		getCss: function (styleName) {
			var value;
			if (this.node.currentStyle) {
				value = this.node.currentStyle[styleName];
				if (value == 'auto' && styleName == 'width') {
					value = this.node.clientWidth;
				}
				if (value == 'auto' && styleName == 'height') {
					value = this.node.clientHeight;
				}
				if (styleName == 'opacity' && this.supportFilter() && !this.supportOpacity()) {
					var opactiyRex = /opacity=(\d{1,3})/;
					var filterString = this.node.currentStyle['filter'];
					if (opactiyRex.test(filterString)) {
						value = parseFloat(RegExp.$1) / 100;
					}
				}
				return value;
			} else if (window.getComputedStyle) {
				value = window.getComputedStyle(this.node, null).getPropertyValue(this.getSplitName(styleName));
				return value;
			}
		},
		width: function () {
			return this.node.offsetWidth;
		},
		height: function () {
			return this.node.offsetHeight;
		},
		setCss: function (styleName, value) {
			if (styleName == 'opacity') {
				if (this.supportOpacity()) {
					this.node.style.opacity = value;
				} else if (this.supportFilter()) {
					this.node.style.zoom = 1;
					this.node.style.filter = 'alpha(opacity=' + (parseFloat(value) * 100) + ')';
				}
				return;
			}
			regExpNoneUnit = /(?:zIndex|opacity|zoom)/i;
			if (!regExpNoneUnit.test(styleName) && typeof value == 'number') {
				this.node.style[this.getCamelName(styleName)] = value + 'px';
				return;
			}
			// alert
			this.node.style[this.getCamelName(styleName)] = value;
		},
		getSplitName: function (styleName) {
			return styleName.replace(/([A-Z])/g, '-$1').toLowerCase();
		},
		getCamelName: function (style_name) {
			return style_name.replace(/-([a-z])/g, function (targetStr) {
				return targetStr.slice(1).toUpperCase();
			});
		},
		addClass: function (value) {
			var classNames = (value || '').split(/\s+/);
			if (this.node.className) {
				var className = ' ' + this.node.className + ' ',
					setClass = this.node.className;
				for (var i = 0, len = classNames.length; i < len; i++) {
					if (className.indexOf(' ' + classNames[i] + ' ') < 0) {
						setClass += ' ' + classNames[i];
					}
				}
				this.node.className = dk.trim(setClass);
			} else {
				this.node.className = value;
			}
		},
		removeClass: function (value) {
			var classNames = (value || '').split(/\s+/);
			if (this.node.className) {
				if (value) {
					var className = (' ' + this.node.className + ' ').replace(/[\n\t]/g, ' ');
					for (var i = 0, len = classNames.length; i < len; i++) {
						className = className.replace(' ' + classNames[i] + ' ', ' ');
					}
					this.node.className = dk.trim(className);
				} else {
					this.node.className = '';
				}
			}
		},
		hasClass: function (value) {
			return this.node.className.indexOf(value) > -1;
		},
		supportOpacity: function () {
			return typeof document.createElement("div").style.opacity != 'undefined';
		},
		supportFilter: function () {
			return typeof document.createElement('div').style.filter != 'undefined';
		},
		remove: function(){
			return this.node.parentNode.removeChild(this.node);
		},
		tagName: function(){
			return this.node.tagName.toLowerCase();
		},
		getPosition: function(){
			var target = this.node;
			if (!target) {
				return null;
			}
			var left = 0,
				top = 0;
			do {
				left += target.offsetLeft || 0;
				top += target.offsetTop || 0;
				target = target.offsetParent;
			} while (target);
			return {
				left: left,
				top: top
			};
		}
	};
	
	dkit.$$ = function(node){
		return new _$(node);
	};
	/***** dkit logs *****/
	var console = function(id) {
        id = id || 'defaultDebugLogs';
        var logsWindow = null;
        var initWindow = function () {
            logsWindow = document.createElement('ol');
            logsWindow.setAttribute('id', id);
            var winStyle = logsWindow.style;
            winStyle.position = 'fixed';
            winStyle.top = '10px';
            winStyle.right = '10px';
            winStyle.width = '300px';
            winStyle.height = '600px';
            winStyle.overflow = 'auto';
            winStyle.border = '1px solid #ccc';
            winStyle.background = '#fff';
            winStyle.padding = 0;
            winStyle.margin = 0;
            document.body.appendChild(logsWindow);
        };
        this.writeRow = function (message) {
            logsWindow || initWindow();
            var newItem = document.createElement('li');
            newItem.style.padding = '2px';
            newItem.style.margin = '0 0 1px 0';
            newItem.style.background = '#eee';
            if (typeof(message) == 'undefined') {
                newItem.innerHTML = '<span style=\"color:#f90;\">Message is undefined</span>';
            } else {
                newItem.innerHTML = message;
            }
            logsWindow.appendChild(newItem);
        };
    }

    console.prototype = {
       write: function (message) {

            if (typeof(message) == 'string' && message.length == 0) {
                return this.writeRow('<span style=\"color:#900;\">warning:</span> empty message');
            }
            if (typeof(message) != 'string' && typeof(message) != 'undefined') {
				if(message === null){
					return this.writeRow('<span style=\"color:#900;\">Message is null</span>');
				}
                if (message.toString){
					return this.writeRow(message.toString());
				}
                else{
					return this.writeRow(typeof(message));
				}
            }
            if (typeof(message) == 'undefined') {
                return this.writeRow('<span style=\"color:#f90;\">Message is undefined</span>');
            }
            message = message.replace(/</g, "&lt;").replace(/</g, "&gt;");
            return this.writeRow(message);
        },
        header: function (message) {
            return this.writeRow(message);
        }
    };
	
	dkit.console = new console();
	
	/***********expand the original Object***********/
	String.prototype.trim = function(){
		 return (this || "").replace(/^(\s|\u00A0)+|(\s|\u00A0)+$/g, "");
	};
	
	if(!win.dkit) {
		win.dkit = dkit;
		win.dkit.version = '0.1';
	}
})(window);/**
 * Author:	DK
 * Email:	dukai86@gmail.com
 * Blog:	http://www.dklogs.net
 */

var BasePopBox = function(options){
	this.title = "Message";
	this.options = {
		custombtns: [],
		title: '提示信息',
		width: 300,
		height: 0,
		dragable: false,
		isBlock: true,
		color:'#4d4d4d',
		border:0,
		background:'#0078c9'
	};
	if(options){
		for(var key in options){
			this.options[key] = options[key];
		}
	}

	this.customEvents = {};
	this.model = null;
	this.isBlock = true;
	this.container_dom = null;
	this.content_dom = null;
	this.title_dom = null;
	this.header_dom = null;
	this.ctrlbtns_dom = null;
	this.coverLayer_dom = null;
	this.funcbtns_dom = null;
	this.funcBtns = {};
	
	
	var self = this;
	
	self.initialize = function(){
		if(!self.container_dom){
			self.initializeUI();
			self.initializeEvents();
		}
	};
	
	self.initializeUI = function(){
		self.funcBtns.cancel = dkit.$c('a', null, 'dkit-popbox-btn-cancel');
		self.funcBtns.cancel.innerHTML = '取消';
		self.funcBtns.cancel.btntype = 'cancel';
		self.funcBtns.confirm = dkit.$c('input', 'dkit-popbox-confirm', 'dkit-popbox-btn-confirm');
		self.funcBtns.confirm.value = "确定";
		self.funcBtns.confirm.btntype = 'confirm';
		self.funcBtns.custom = dkit.$c('a', null, 'dkit-popbox-btn-custom');
		self.funcBtns.custom.btntype = 'custom';
		//获取浏览器窗口尺寸
		var browserSize = dkit.getBrowserSize();
		var docSize = dkit.getDocSize();
		
		//判断是否显示遮罩层
		if(self.options.isBlock){
			self.coverLayer_dom = dkit.$c('div');
			var coverHeight = docSize.height > browserSize.height ? docSize.height : browserSize.height;
			dkit.$$(self.coverLayer_dom).css({display:'none', position: 'absolute', background: '#000', opacity: '.5', top: 0, left: 0, width: '100%', height: coverHeight});
			document.body.appendChild(self.coverLayer_dom);
		}
		//生成popbox容器层
		self.container_dom = dkit.$c('div', null, 'dkit-popbox');
		var height = '';
		if(self.options.height == 'fill_parent'){
			height = dkit.getBrowserSize().height;
			height -= 100;
		}else if(self.options.height == 0){
			height = '';
		}
		dkit.$$(self.container_dom).css({'zIndex': 9999999, 'display': 'block', 'width': self.options.width, 'height': height, 'background': self.options.background, 'border':self.options.border}); 
		document.body.appendChild(self.container_dom);
		//生成头部
		self.header_dom = dkit.$c('div', null, 'dkit-popbox-header');
		self.title_dom = dkit.$c('span');
		if(self.options.title){
			self.title = self.options.title;
		}
		self.title_dom.innerHTML = self.title;
		//控制按钮容器
		self.ctrlbtns_dom = dkit.$c('div', null, 'dkit-popbox-ctrlbtns');
		self.close_ctrlbtn = dkit.$c('a', null, 'dkit-popbox-ctrlbtns-close');
		self.close_ctrlbtn.btntype = 'close';
		self.ctrlbtns_dom.appendChild(self.close_ctrlbtn);
		self.header_dom.appendChild(self.title_dom);
		self.header_dom.appendChild(self.ctrlbtns_dom);
		//内容容器
		self.content_dom = dkit.$c('div', null, 'dkit-popbox-content');
		// 改过，新增加一行
		dkit.$$(self.content_dom).css({'color': self.options.color});
		//功能按钮容器
		self.funcbtns_dom = dkit.$c('div', null, 'dkit-popbox-btnbox');
		self.renderBtns();
		
		self.container_dom.appendChild(self.header_dom);
		self.container_dom.appendChild(self.content_dom);
		self.container_dom.appendChild(self.funcbtns_dom);
		document.body.appendChild(self.container_dom);
	};
	
	self.initializeEvents = function(){
		dkit.addEvent(self.container_dom, 'click', function(e){
			var target = e.target;
			switch(target.btntype){
				case 'min':
					//alert('min');
					break;
				case 'close':
					self.close();
					break;
				case 'confirm':
					self.confirm();
					break;
				case 'cancel':
					self.cancel();
					break;
				case 'custom':
					self.execCustomBtnsEvent(target.funcid);
					break;
				default:
					break;
			}
		});
		dkit.addEvent(document, 'keypress', function(e){
			if(e.keyCode == 27){
				self.close();
			}
		});
		//注册拖动事件
		if(self.options.dragable){
			dragManager.regist(self.header_dom, self.container_dom);
		}
	};
	
	self.execCustomBtnsEvent = function(btnId){
		var customBtns = self.options.custombtns;
		btnId = parseInt(btnId);
		customBtns[btnId]['func'].call(self);
	};
	
	self.setContent = function(message){
		self.content_dom.innerHTML = message;
	};
	
	self.setTitle = function(title){
		self.title_dom.innerHTML = title;
	}
	
	self.setBoxPosition = function(left, top){
		if(arguments.length < 2){
			var browserSize = dkit.getBrowserSize();
			var width = dkit.$$(self.container_dom).width();
			var height = dkit.$$(self.container_dom).height();
			var left = Math.floor((browserSize.width / 2) - (width / 2));
			var top = Math.floor((browserSize.height / 2) - (height / 2));
		}
		//dkit.$$(self.container_dom).css({'left': left, 'top': top});
	};
	
	self.renderBtns = function(){};//AbstractMethod	
	self.onShowEvent = function(){};
	self.onCloseEvent = function(){};
	
	self._show = function(){
		self.onShowEvent();
		// 打开背景层
		if(self.options.isBlock){
			//$(".body_normal").attr("class", "is_photo_box");
			var height = $('#container').height()
			if (height < $(window).height()) {
				height = $(window).height()	
			}
			// 高度的设置是新加的，测试中
			$("#you_cant_see_me_alert").css('height', height + 10 + 'px').css("z-index", "1000000").css("display", "block");
		} else {
			// 显示透明背景
			$("#you_never_see_me_alert").css("z-index", "1000000").css("display", "block");
		}
		self.container_dom.style.display = 'block';
		self.setBoxPosition();
		
		$("#dkit-popbox-confirm").focus();
	};
	
	self.show = function(){
		self._show();
	};
	
	self.close = function(){
		self.onCloseEvent();
		
		//$(".is_photo_box").attr("class", "body_normal");
		$("#you_cant_see_me_alert").css("z-index", "9").hide();
		$("#you_never_see_me_alert").css("z-index", "9").hide();
		
		if(self.options.isBlock) {
			self.coverLayer_dom.style.display = 'none';
		}
		self.container_dom.style.display = 'none';
	};
	self.onConfirmEvent = function(){
		
	};
	self.confirm = function(){
		self.onConfirmEvent();
		self.close();		
	};
	
	self.onCancelEvent = function(){
		
	};
	self.cancel = function(){
		self.onCancelEvent();
		self.close();
	};
};

BasePopBox.Model = {
	'dialog':	0,
	'alert':	1,
	'confirm':	2,
	'toast': 	3
};

var DialogBox = function(id, options){ //extends BasePopBox
	BasePopBox.call(this, options);
	this.model = BasePopBox.Model.dialog;

	var type = /<[^>]+?>/.test(id);
	if(!type){
		var node = dkit.$(id);
		node.style.display = '';
		this.title = node.getAttribute('boxtitle');
	}
	this.renderBtns = function(){
		if(this.options && this.options.custombtns){
			this.funcbtns_dom.style.display = 'block';
			var custombtns = this.options.custombtns;
			for(var i = 0, len = custombtns.length; i < len; i ++){
				var btn = this.funcBtns.custom.cloneNode(true);
				btn.btntype = 'custom';
				btn.innerHTML = custombtns[i]['name'];
				btn.funcid = i;
				btn.custombtn = 'custombtn';
				this.funcbtns_dom.appendChild(btn);
			}
		}else{
			this.funcbtns_dom.style.display = 'none';
		}
		
	};
	this.initializeUI();
	this.initializeEvents();
	if(!type){
		this.content_dom.appendChild(node);
	}else{
		this.content_dom.innerHTML = id;
	}
};

var FrameBox = function(url, options){
	if(!options){
		options = {};
		options.dragable = false;
	}else if(options.dragable === undefined){
		
	}
	BasePopBox.call(this, options);
	
	this.renderBtns = function(){
		this.funcbtns_dom.style.display = 'none';
	};
	this.initializeUI();
	this.initializeEvents();
	var height = dkit.getBrowserSize().height;
	height -= 100;
	this.content_dom.innerHTML = '<iframe src="' + url + '" frameborder="0" width="100%" height="' + height + '"></iframe>';
}

var AlertBox = function(message, options){
	BasePopBox.call(this, options);
	this.model = BasePopBox.Model.alert;
	this.renderBtns = function(){
		this.funcbtns_dom.style.display = "block";
		this.funcbtns_dom.appendChild(this.funcBtns.confirm);
	};
	
	this.show = function(message){
		if(message && message != ''){
			this.setContent(message);
		}
		this._show();
	}
	
	this.initializeUI();
	this.initializeEvents();
	this.setContent(message);
};

var ConfirmBox = function(message, options){
	var options = options || {};
	options.background = "#fff";
	options.width = 340;
	options.border = "12px solid #d6d6d6\0;"
	
	BasePopBox.call(this, options);
	
	this.renderBtns = function(){
		this.funcbtns_dom.appendChild(this.funcBtns.confirm);
		this.funcbtns_dom.appendChild(this.funcBtns.cancel);
	};
	
	this.show = function(positiveEvent, negativeEvent){
		if(positiveEvent)
			this.onConfirmEvent = positiveEvent;
			return true;
		if(negativeEvent)
			this.onCancelEvent = negativeEvent;
		this._show();
	};
	
	this.initializeUI();
	this.initializeEvents();
	this.setContent(message);
};

var ToastBox = function(message, duration, options){ 
	var options = options || {};
	//alert(options.isBlock);
	if(!duration){
		duration = 3000;
	}
	BasePopBox.call(this, options);

	var self = this; 
	this.renderBtns = function(){
		this.funcbtns_dom.style.display = "none";
	};
	
	this.onShowEvent = function(){ 
		setTimeout(self.close, duration);		
	};
	
	this.initializeUI();
	this.initializeEvents();
	//this.header_dom.style.display = 'none';
	this.content_dom.style.paddingBottom = 0;
	this.content_dom.style.marginBottom = "10px";
	this.content_dom.style.borderRadius = "0 0 5px 5px";
	this.setContent(message);
};
//Toast Box 持续时间
ToastBox.long = 2000;
ToastBox.noraml = 1000;
ToastBox.short = 5000;
(function(a) {
	a.fn.maiPlayer = function(c) {
		var b = {
			oPlay: null,
			speedSwitch:30000000,
			speedAnimate: 500,
			showPage: 0,
			playerWidth: 0,
			autoPlay: true,
			flipButton: true,
			pageButton: true,
			playerBg: true,
			numPage: false,
			imageTitle: false,
			imageContent: false,
			switchActionAuto: "roll",
			switchActionPage: "roll",
			switchActionFlip: "roll",
			textDisplay: 0,
			textSpeed: 500,
			lazy:false
		};
		var c = a.extend(b, c);
		this.each(function() {
			var p = a(this);
			var n = "";
			var h = 0;
			var i = 0;
			var j = null;
			var d = [];
			a(p).find("li img").parents("ul").addClass("ul-img").css("position", "relative");
			h = a(p).find(".ul-img li").length;
			if (c.playerWidth) {
				i = c.playerWidth;
				a(p).css("width", i + "px");
				a(p).find(".ul-img li").css("width", i + "px");
				a(p).find("img").css("width", i + "px");
				a(p).find(".bg:first").css("width", i + "px")
			} else {
				i = a(p).find(".ul-img li:first").width()
			}

			if (c.playerHeight) {
				iHeight = c.playerHeight;
				a(p).css("height", iHeight + "px");
				a(p).find(".ul-img").css("height", iHeight + "px");
				a(p).find(".ul-img li").css("height", iHeight + "px");
				a(p).find("img").css("height", iHeight + "px")
			}
			a(p).find(".ul-img li").each(function() {
				var q = a(p).find(".ul-img li").index(this);
				d[q] = a(p).find(".ul-img img").eq(q).attr("title");
				a(p).find(".ul-img img").eq(q).removeAttr("title")
			});
			if (c.imageTitle || c.imageContent) {
				var k = a('<ul class="ul-text"></ul>');
				a(k).insertAfter(a(p).find(".ul-img"));
				a(p).find(".ul-img li").each(function() {
					var s = a("<li></li>");
					var q = a(p).find(".ul-img li").index(this);
					if (c.imageTitle) {
						var t = a("<h2></h2>");
						a(t).text(d[q]);
						a(s).append(t)
					}
					if (c.imageContent) {
						var r = a("<p></p>");
						var u = a(p).find(".ul-img img").eq(q).attr("alt");
						a(r).text(u);
						a(s).append(r)
					}
					a(k).append(s)
				});
				a(p).find(".ul-text").width(i * h);
				a(p).find(".ul-text").height(a(p).find(".bg:first").height())
			}
			a(p).find(".ul-img").width(i * h + 1);
			if (c.flipButton) {
				a(p).find(".next:first").click(function() {
					if (c.switchActionFlip == "roll") {
						l(a(p).find(".ul-img"), 1);
						if (c.imageTitle || c.imageContent) {
							l(a(p).find(".ul-text"), 0)
						}
					} else {
						if (c.switchActionFlip == "opacity") {
							if (c.showPage == h - 1) {
								c.showPage = 0
							} else {
								c.showPage++
							}
							f(a(p).find(".ul-img"), c.showPage);
							f(a(p).find(".ul-text"), c.showPage);
							e(a(p).find(".num span").eq(c.showPage), "on")
						}
					}
					if(b.lazy){
						a(p).find("li:gt(0) .lazy-after").lazyload({"event":"mouseover"});
						a(p).find("li:gt(0) .lazy-after").trigger("mouseover")
					}
					if(c.showPage==5){
						$(".num").hide();
						$(".faTopic").fadeIn();
					}else{
						$(".num").show();
						$(".faTopic").hide();
					}
				});
				a(p).find(".prev:first").click(function() {
					
					if (c.switchActionFlip == "roll") {
						l(a(p).find(".ul-img"), -1);
						if (c.imageTitle || c.imageContent) {
							l(a(p).find(".ul-text"), 0)
						}
					} else {
						if (c.switchActionFlip == "opacity") {
							if (c.showPage == 0) {
								c.showPage = h - 1
							} else {
								c.showPage--
							}
							f(a(p).find(".ul-img"), c.showPage);
							f(a(p).find(".ul-text"), c.showPage);
							e(a(p).find(".num span").eq(c.showPage), "on")
						}
					}
					if(b.lazy){
						a(p).find("li:gt(0) .lazy-after").lazyload({"event":"mouseover"});
						a(p).find("li:gt(0) .lazy-after").trigger("mouseover")
					}
					if(c.showPage==5){
						$(".num").hide();
						$(".faTopic").fadeIn();
					}else{
						$(".num").show();
						$(".faTopic").hide();
					}
				})
			} else {
				a(p).find(".next:first").css("display", "none");
				a(p).find(".prev:first").css("display", "none")
			}
			if (c.showPage) {
				a(p).find(".ul-img").css("left", -i * c.showPage + "px");
				a(p).find(".ul-text").css("left", -i * c.showPage + "px")
			}
			
			if (c.pageButton) {
				
				n = "";
				a(p).find(".ul-img li").each(function() {
					n += "<span></span>"
				});
				a(p).find(".num:first").html(n);
				a(p).find(".num span:first").addClass("on");
				e(a(p).find(".num span").eq(c.showPage), "on");
				a(p).find(".num span").click(function() {
					var q = a(p).find(".num span").index(this);
					if (c.switchActionPage == "roll") {
						c.showPage = 0;
						l(a(p).find(".ul-img"), q);
						l(a(p).find(".ul-text"), 0)
					} else {
						if (c.switchActionPage == "opacity") {
							c.showPage = q;
							f(a(p).find(".ul-img"), c.showPage);
							f(a(p).find(".ul-text"), c.showPage);
							e(a(p).find(".num span").eq(c.showPage), "on")
						}
					}
					if (c.numPage) {
						a(this).text(a(p).find(".num span").index(this) + 1)
					}
					if(c.showPage==5){
						$(".num").hide();
						$(".faTopic").fadeIn();
					}else{
						$(".num").show();
						$(".faTopic").hide();
					}
				})
			}
			if (!c.playerBg) {
				a(p).find(".bg:first").css("display", "none")
			}
			function l(r, q) {
				if (r.is(":animated") == false) {
					c.showPage += q;
					if (c.showPage != -1 && c.showPage != h) {
						r.animate({
							left: -c.showPage * i + "px"
						},
						c.speedAnimate)
					} else {
						if (c.showPage == -1) {
							c.showPage = h - 1;
							r.css({
								left: -(i * (c.showPage - 1)) + "px"
							});
							r.animate({
								left: -(i * c.showPage) + "px"
							},
							c.speedAnimate)
						} else {
							if (c.showPage == c.showPage) {
								c.showPage = 0;
								r.css({
									left: -i + "px"
								});
								r.animate({
									left: 0 + "px"
								},
								c.speedAnimate)
							}
						}
					}
					e(a(p).find(".num span").eq(c.showPage), "on")
				}
			}
			function f(s, r) {
				var q = (s.css("left") != -r * i + "px");
				if (q) {
					s.fadeOut(20,
					function() {
						s.css("left", -r * i + "px");
						s.fadeIn(500)
					})
				}
			}
			function m() {
				j = setInterval(function() {
					if (c.switchActionAuto == "roll") {
						l(a(p).find(".ul-img"), 1)
					} else {
						if (c.switchActionAuto == "opacity") {
							c.showPage++;
							if (c.showPage == h) {
								c.showPage = 0
							}
							f(a(p).find(".ul-img"), c.showPage);
							e(a(p).find(".num span").eq(c.showPage), "on")
						}
					}
					if (c.imageTitle || c.imageContent) {
						l(a(p).find(".ul-text"), 0)
					}
				},
				c.speedSwitch)
			}
			function o() {
				if (j) {
					clearInterval(j)
				}
			}
			a(p).hover(function() {
				o();
				if (c.textDisplay == 1) {
					a(p).find(".bg:first").slideUp(c.textSpeed);
					a(p).find(".ul-text:first").slideUp(c.textSpeed);
				} else {
					if (c.textDisplay == 2) {
						a(p).find(".bg:first").slideDown(c.textSpeed);
						a(p).find(".ul-text:first").slideDown(c.textSpeed)
					}
				}
			},
			function() {
				if (c.autoPlay) {
					m()
				}
				if (c.textDisplay == 1) {
					a(p).find(".bg:first").slideDown(c.textSpeed);
					a(p).find(".ul-text:first").slideDown(c.textSpeed)
				} else {
					if (c.textDisplay == 2) {
						a(p).find(".bg:first").slideUp(c.textSpeed);
						a(p).find(".ul-text:first").slideUp(c.textSpeed)
					}
				}
			});
			if (c.autoPlay) {
				m()
			}
			function g(q, r) {}
			function e(r, q) {
				r = a(r) ? a(r) : r;
				r.addClass(q).siblings().removeClass(q)
			}
		})
	}
})(jQuery);
